package com.tvb.pojo;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name="login_role")
public class LoginRole {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	@Column(name="role_code")
	private Integer roleCode;//角色简码
	
	@Column(name="role_name")
	private String roleName;//角色名称
	
	@Column(name="memo")
	private String memo;//描述
	
	@Column(name="op_name")
	private String opName;//创建人名字
	
	@Column(name="op_date")
	private Date opDate;//创建时间
	
	
	//多对多通过中间表维护关系
	@ManyToMany(cascade={CascadeType.REMOVE},fetch=FetchType.LAZY)
	@JoinTable(name="login_role_pur",
		joinColumns={@JoinColumn(name="role_code",referencedColumnName="role_code")},
		inverseJoinColumns={@JoinColumn(name="pur_id",referencedColumnName="id")})
	private Set<LoginPurview> loginPurviews = new HashSet<LoginPurview>();
	
	//多对多由mappedBy指定双向维护关系
	@ManyToMany(mappedBy="roles")
	private Set<LoginUser> loginUsers = new HashSet<LoginUser>();
	
	@Transient
	private Set<String> purviews = new HashSet<String>();//对应可以反问的path
	public Set<LoginPurview> getLoginPurviews() {
		return loginPurviews;
	}
	public void setLoginPurviews(Set<LoginPurview> loginPurviews) {
		this.loginPurviews = loginPurviews;
	}
	public Set<LoginUser> getLoginUsers() {
		return loginUsers;
	}
	public void setLoginUsers(Set<LoginUser> loginUsers) {
		this.loginUsers = loginUsers;
	}

	
	public Set<String> getPurviews() {
		return purviews;
	}
	public void setPurviews(Set<String> purviews) {
		this.purviews = purviews;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Integer getRoleCode() {
		return roleCode;
	}
	public void setRoleCode(Integer roleCode) {
		this.roleCode = roleCode;
	}
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	public String getOpName() {
		return opName;
	}
	public void setOpName(String opName) {
		this.opName = opName;
	}
	public Date getOpDate() {
		return opDate;
	}
	public void setOpDate(Date opDate) {
		this.opDate = opDate;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
